package com.db4o.odbgen.plugins.java.maingenerator.typedxmlschema;

import com.db4o.internal.odbgen.StringUtils;
import com.db4o.odbgen.plugins.xmlschema.Element;

/**
 * 
 * Represents getter and setter methods.
 * Getter/setters share the same base name and the same type.
 * @author liviug
 */
public class TSGetterSetter implements XmlElement{

    private String _baseName;
    private Element _element;
    private DataType _type;
    private boolean _hasGetter;
    private boolean _hasSetter;

    /**
     * Constructs a getter/setter given it's elements.
     * @param element
     * @param baseName The base name shared by both the getter and the setter.
     * @param type The type of the data represented by the getter/setter.
     * @param hasGetter Tells whether there is a getter.
     * @param hasSetter Tells whether there is a setter.
     */
    public TSGetterSetter(
            Element element, 
            String baseName, 
            DataType type, 
            boolean hasGetter, 
            boolean hasSetter
            ){
        this._element = element;
        this._baseName = baseName;
        this._type = type;
        this._hasGetter = hasSetter;
        this._hasSetter = hasGetter;
    }
    
    /**
     * See {@link XmlElement} for details.
     */
    @Override
    public Element getElement() {
        return this._element;
    }

    /**
     * Represents the base name of the getter/setter.
     */
    public String getBaseName(){
        return this._baseName;
    }
    
    /**
     * Represents the type of the getter/setter.
     */
    public DataType getType(){
        return this._type;
    }

    /**
     * Tells whether the getter is implemented or not.
     */
    public boolean hasGetter(){
        return this._hasGetter;
    }
    
    /**
     * Tells whether the setter is implemented or not.
     */
    public boolean hasSetter(){
        return this._hasSetter;
    }

    /**
     * Returns a string representing this object.
     * This is used for debug purposes.
     * @param tabs Number of tabs to indent.
     */
    String toString(int tabs) {
        StringBuilder res = new StringBuilder();
        
        res.append(String.format("%sgettersetter", StringUtils.tabs(tabs)));
        res.append(StringUtils.newLine());

        res.append(String.format("%sbasename=%s",
                StringUtils.tabs(tabs+1),
                this.getBaseName()
                ));
        res.append(StringUtils.newLine());

        res.append(String.format("%shasgetter=%s",
                StringUtils.tabs(tabs+1),
                this.hasGetter()
                ));
        res.append(StringUtils.newLine());

        res.append(String.format("%shassetter=%s",
                StringUtils.tabs(tabs+1),
                this.hasSetter()
                ));
        res.append(StringUtils.newLine());

        
        res.append(String.format("%stype=%s",
                StringUtils.tabs(tabs+1),
                this.getType().toString()
                ));
        res.append(StringUtils.newLine());
        
        return res.toString();
    }
}
